package Case;
//死锁演示
public class DeadLock {
    static Object objA = new Object();//锁对象
    static Object objB = new Object();//锁对象

    public static void main(String[] args) {
    Runnable runnable=()->{
      while (true){
          if(Thread.currentThread().getName().equals("线程1")) {
              synchronized (objA) {
                  System.out.println("线程1拿到了A锁,准备拿B锁");
                  synchronized (objB) {
                      System.out.println("线程1拿到了B锁");
                  }
              }
          }else {
              synchronized (objB) {
                  System.out.println("线程2拿到了B锁,准备拿A锁");
                  synchronized (objA) {
                      System.out.println("线程2拿到了A锁");
                  }
              }
          }
      }
    };

    new Thread(runnable,"线程1").start();
    new Thread(runnable,"线程2").start();
    }
}
